// services/modalState.ts
import { ref, Ref } from 'vue'
import type { ModalConfig } from './modal'

// 创建全局状态
const createModalState = () => {
  return {
    visible: ref(false),
    config: ref<ModalConfig>({}),
  }
}

// 获取或创建全局状态
export const getModalState = (): { visible: Ref<boolean>; config: Ref<ModalConfig> } => {
  if (!(window as any).__MODAL_STATE__) {
    ;(window as any).__MODAL_STATE__ = createModalState()
  }
  return (window as any).__MODAL_STATE__
}

// 清理全局状态（用于测试或特殊情况）
export const clearModalState = () => {
  delete (window as any).__MODAL_STATE__
}
